package com.newy.core.web;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.newy.service.sys.UserService;

/**
 * 会话监听类，用于监听会话创建和销毁 
 * @author linzongxue
 *
 */
public class SessionListener implements HttpSessionListener {
	private static Logger logger = LoggerFactory.getLogger(SessionListener.class);

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		logger.debug("创建会话：" + event.getSession().getId());
	}

	/**
	 * 当会话销毁时通知UserManager类
	 */
	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		logger.debug("销毁会话：" + event.getSession().getId());
		
		String sessionId = event.getSession().getId();
		AppContext.getBean(UserService.class).deleteCurrentLoginInfo(sessionId, false);
	}

}
